Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: wrap the zenoh session with a shared pointer #333

Merged
merged 5 commits into from
Dec 10, 2024

Conversation

YuanYuYuan
Copy link
Contributor

Copy link
Collaborator

@clalancette clalancette left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I generally like the idea here, but I think we need to do some more work particularly in the ClientData class. I've left a detailed proposal in there.

rmw_zenoh_cpp/src/detail/rmw_client_data.cpp Outdated Show resolved Hide resolved
rmw_zenoh_cpp/src/detail/rmw_publisher_data.cpp Outdated Show resolved Hide resolved
Copy link
Contributor

@ahcorde ahcorde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@clalancette
Copy link
Collaborator

These changes are already included in the zenoh_c to zenoh_cpp PR https://github.com/ros2/rmw_zenoh/pull/327/files#diff-124e1086db3e5f3edb76619bd65943a900a963ef671e014c817d3bf27d803908

I do think we should get this one in first, and then go for the switch to zenoh-cpp. That will allow us to concentrate on one thing at a time, and I think this one is largely ready to go (with my one big comment up above still to be addressed).

@YuanYuYuan
Copy link
Contributor Author

These changes are already included in the zenoh_c to zenoh_cpp PR https://github.com/ros2/rmw_zenoh/pull/327/files#diff-124e1086db3e5f3edb76619bd65943a900a963ef671e014c817d3bf27d803908

I do think we should get this one in first, and then go for the switch to zenoh-cpp. That will allow us to concentrate on one thing at a time, and I think this one is largely ready to go (with my one big comment up above still to be addressed).

Hi @clalancette, I'm trying to understand the underlying issue with the client and the request-in-flight. But I'm wondering why we must clone a session for each request. It seems to me either the callback or the client_data_drop doesn't utilize the session.

@clalancette
Copy link
Collaborator

Hi @clalancette, I'm trying to understand the underlying issue with the client and the request-in-flight. But I'm wondering why we must clone a session for each request. It seems to me either the callback or the client_data_drop doesn't utilize the session.

Doesn't client_data_drop implicitly use the session, by the fact that it being called by the internals of Zenoh? If that is not the case, then indeed we do not need to hold onto this here. But in that case, I think we would want to hold onto the session for the lifetime of ClientData (i.e. take the reference in the constructor).

@YuanYuYuan
Copy link
Contributor Author

YuanYuYuan commented Dec 9, 2024

Doesn't client_data_drop implicitly use the session, by the fact that it being called by the internals of Zenoh? If that is not the case, then indeed we do not need to hold onto this here. But in that case, I think we would want to hold onto the session for the lifetime of ClientData (i.e. take the reference in the constructor).

  1. The client_data_drop is part of the closure. It doesn't really depend on a zenoh session but a zenoh runtime which is global and internal.
  2. But whether the callback is triggered or not makes a difference. I ran some quick tests and discovered that in the recent zenoh version, a get request sent to a remote queryable won't trigger the callback if the get session is closed between the time the queryable receives the request and sends back the reply. The question is do we want to make sure each reply is handled even after the session is closed? If the answer is yes, then we need to clone the session for every request. Otherwise, we don't.
  3. We recently introduced the Querier, which works like a session.put vs publisher. This means we can keep the Querier rather than a session as we do for the other rmw data in the future.

@clalancette
Copy link
Collaborator

  • But whether the callback is triggered or not makes a difference. I ran some quick tests and discovered that in the recent zenoh version, a get request sent to a remote queryable won't trigger the callback if the get session is closed between the time the queryable receives the request and sends back the reply. The question is do we want to make sure each reply is handled even after the session is closed? If the answer is yes, then we need to clone the session for every request. Otherwise, we don't.

No, I don't think we need to handle the reply after the session is closed. In our case, the session being closed is the result of the context being shutdown, and after that point nothing in the higher layers can handle anything new anyway.

OK, so in that case, I'm going to withdraw my previous comment about fixing it (though I will open a separate PR doing that for the ClientData, which does need to be kept alive). I'll put a different comment about possibly moving the Session reference count elsewhere.

Copy link
Collaborator

@clalancette clalancette left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more change to make, then I think this is good to go.

@@ -406,6 +409,7 @@ rmw_ret_t ClientData::send_request(
if (context_impl == nullptr) {
return RMW_RET_INVALID_ARGUMENT;
}
sess_ = context_impl->session();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need this, right? Because we are holding onto the session while this ClientData is alive, this is an unnecessary additional reference count, and I think it is enough to just keep this in the constructor.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. It's misplaced. Resolved in 416f430

@YuanYuYuan
Copy link
Contributor Author

Rebase it against the latest rolling.

@clalancette clalancette merged commit 8bca9d7 into ros2:rolling Dec 10, 2024
6 checks passed
@YuanYuYuan YuanYuYuan deleted the refactor/shareable-session branch December 11, 2024 07:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Issues caused by not shutting down the contained entity
3 participants